package com.jiawa.train.batch.controller.admin;

import com.jiawa.train.batch.req.TrainQueryReq;
import com.jiawa.train.batch.req.TrainSaveReq;
import com.jiawa.train.batch.resp.PageResp;
import com.jiawa.train.batch.resp.TrainQueryResp;
import com.jiawa.train.batch.service.TrainService;
import com.jiawa.train.batch.service.train_seatService;
import com.jiawa.train.common.resp.CommonResp;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/train")
public class TrainAdminController {

    @Autowired
    private TrainService trainService;
    @Autowired
    private train_seatService train_seatService;

    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody TrainSaveReq req) {
        trainService.save(req);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainQueryResp>> queryList(@Valid  TrainQueryReq req) {
        PageResp<TrainQueryResp> list = trainService.queryList(req);
        return new CommonResp<>(list);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable("id") Long id) {
        trainService.delete(id);
        return new CommonResp<>();
    }

    @GetMapping("/query-all")
    public CommonResp<List<TrainQueryResp>> queryList() {
        List<TrainQueryResp> list = trainService.queryAll();
        return new CommonResp<>(list);
    }

    @GetMapping("/gen-seat/{trainCode}")
    public CommonResp<Object> genSeat(@PathVariable("trainCode") String trainCode) {
        train_seatService.genTrainSeat(trainCode);
        return new CommonResp<>();
    }

}
